package homeWork.day3;

import java.util.Calendar;
import java.util.Scanner;

/**2018-03-25
 * 输入一个生产日期格式"yyyy-MM-dd",再输入一个数字(保质期的天数)。
 * 然后经过计算输出促销日期，促销日期为:该商品过期日前2周的周三
 * @author Bonnie
 * 
 */
public class Test04 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入生产日期:");
        String pDay = input.nextLine();
        System.out.println("请输入保质期(天数):");
        String keepDay = input.nextLine();
        String[] t = pDay.split("-");
        int year = Integer.parseInt(t[0]);
        int month = Integer.parseInt(t[1])-1;
        int day = Integer.parseInt(t[2]);
        Calendar c1 = Calendar.getInstance();
        c1.set(Calendar.DATE,day);
        c1.set(Calendar.MONTH,month);
        c1.set(Calendar.YEAR,year);
        c1.add(Calendar.DATE,Integer.parseInt(keepDay));
        System.out.println("保质期到"+c1.get(Calendar.YEAR)+"-"+(c1.get(Calendar.MONTH)+1)+"-"+ c1.get(Calendar.DATE));
        if(c1.get(Calendar.DAY_OF_WEEK)>=4||c1.get(Calendar.DAY_OF_WEEK)==1){
            c1.add(Calendar.DATE,-14);
        }else{
            c1.add(Calendar.DATE,-7);
        }
        while(c1.get(Calendar.DAY_OF_WEEK)!=4){
            c1.add(Calendar.DATE,-1);
        }
        System.out.println("促销时间:"+c1.get(Calendar.YEAR)+"-"+(c1.get(Calendar.MONTH)+1)+"-"+ c1.get(Calendar.DATE));
    }
}
